//
//  GYMineLikeProductCell.m
//  GYDemo
//
//  Created by mac on 2018/3/26.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYMineLikeProductCell.h"
#import "Head.h"
@interface GYMineLikeProductCell()<GCAdaptLabelDelegate>
@property (nonatomic,strong) UIImageView *imageIV;
@property (nonatomic,strong) GCAdaptLabel *nameLB;
@property (nonatomic,strong) GCAdaptLabel *typeLB;
//@property (nonatomic,strong) NSArray *types;
//@property (nonatomic,strong) UILabel *countLB;
@property (nonatomic,strong) GCAdaptLabel *priceLB;
@property (nonatomic,strong) GCAdaptLabel *areaLB;
//@property (nonatomic,strong) UILabel *dealCountLB;
@property (nonatomic,strong) UILabel *dateLB;
@end

@implementation GYMineLikeProductCell
#pragma mark - getter and setter
-(UIImageView *)imageIV
{
    if (!_imageIV) {
        _imageIV = [UIImageView new];
        _imageIV.frame = WFCGRectMake(8.5, 12.5, 81, 81);
        _imageIV.contentMode=UIViewContentModeScaleAspectFill;
        _imageIV.clipsToBounds=YES;
        
    }
    return _imageIV;
}
-(GCAdaptLabel *)nameLB
{
    if (!_nameLB) {
        _nameLB = [[GCAdaptLabel alloc]initWithMaxWidth:WFCGFloatX(145.5)];
        _nameLB.x = WFCGFloatX(99.5);
        _nameLB.y = WFCGFloatY(14);
        _nameLB.width = WFCGFloatX(145.5);
        _nameLB.height = WFCGFloatY(21);
        _nameLB.font = SYSTEMFONT(15);
        _nameLB.textColor = Main_Color_Black;
        _nameLB.delegate = self;
    }
    return _nameLB;
}
-(GCAdaptLabel *)typeLB
{
    if (!_typeLB) {
        _typeLB = [[GCAdaptLabel alloc]initWithMaxWidth:WFCGFloatX(60)];
        _typeLB.x = WFCGFloatX(245);
        _typeLB.y = WFCGFloatY(1);
        _typeLB.width = WFCGFloatX(145.5);
        _typeLB.height = WFCGFloatY(14);
        _typeLB.font = SYSTEMFONT(10);
        _typeLB.textColor = Main_Color_Red;
        [WFFunctions WFUIaddbordertoView:_typeLB radius:WFCGFloatY(3) width:0.7f color:Main_Color_Red];
        _typeLB.delegate = self;
    }
    return _typeLB;
}
//-(UILabel *)countLB
//{
//    if (!_countLB) {
//        _countLB = [[UILabel alloc]init];
//        _countLB.x = WFCGFloatX(99.5);
//        _countLB.y = WFCGFloatY(38);
//        _countLB.width = WFCGFloatX(145);
//        _countLB.height = WFCGFloatY(16.5);
//        _countLB.textColor = Main_Color_Gray;
//        _countLB.font = SYSTEMFONT(12);
//    }
//    return _countLB;
//}
-(GCAdaptLabel *)priceLB
{
    if (!_priceLB) {
        _priceLB = [[GCAdaptLabel alloc]initWithMaxWidth:WFCGFloatX(140)];
        _priceLB.x = WFCGFloatX(99.5);
        _priceLB.y = WFCGFloatY(65);
        _priceLB.width = WFCGFloatX(65);
        _priceLB.height = WFCGFloatY(28);
        _priceLB.textColor = Main_Color_Red;
        _priceLB.font = SYSTEMFONT(20);
        _priceLB.delegate = self;
    }
    return _priceLB;
}
-(GCAdaptLabel *)areaLB
{
    if (!_areaLB) {
        _areaLB = [[GCAdaptLabel alloc]initWithMaxWidth:WFCGFloatX(100)];
        _areaLB.x = WFCGFloatX(176.5);
        _areaLB.y = WFCGFloatY(74);
        _areaLB.width = WFCGFloatX(41.5);
        _areaLB.height = WFCGFloatY(14);
        _areaLB.textColor = Main_Color_Gray;
        _areaLB.font = SYSTEMFONT(10);
        _areaLB.backgroundColor = Main_Color_BG;
        _areaLB.delegate = self;
    }
    return _areaLB;
}
//-(UILabel *)dealCountLB
//{
//    if (!_dealCountLB) {
//        _dealCountLB = [[UILabel alloc]init];
//        _dealCountLB.x = WFCGFloatX(99.5);
//        _dealCountLB.y = WFCGFloatY(81);
//        _dealCountLB.width = WFCGFloatX(145);
//        _dealCountLB.height = WFCGFloatY(14);
//        _dealCountLB.textColor = Main_Color_Gray;
//        _dealCountLB.font = SYSTEMFONT(10);
//    }
//    return _dealCountLB;
//}
-(UIButton *)deleteBtn
{
    if (!_deleteBtn) {
        _deleteBtn = [UIButton new];
        _deleteBtn.frame = WFCGRectMake(301.5, 43, 65, 25);
        _deleteBtn.titleLabel.font = SYSTEMFONT(12);
        [_deleteBtn setTitleColor:Main_Color_Red forState:UIControlStateNormal];
        [_deleteBtn setTitle:@"删除收藏" forState:UIControlStateNormal];
        [WFFunctions WFUIaddbordertoView:_deleteBtn radius:_deleteBtn.height / 2 width:0.7f color:Main_Color_Red];
    }
    return _deleteBtn;
}
-(UILabel *)dateLB
{
    if (!_dateLB) {
        _dateLB = [[UILabel alloc]init];
        _dateLB.x = WFCGFloatX(300);
        _dateLB.y = WFCGFloatY(80);
        _dateLB.width = WFCGFloatX(65);
        _dateLB.height = WFCGFloatY(15);
        _dateLB.textColor = Main_Color_LightGray;
        _dateLB.font = SYSTEMFONT(10);
        _dateLB.textAlignment = NSTextAlignmentCenter;
        [WFFunctions WFUIaddbordertoView:_dateLB radius:WFCGFloatY(3) width:0.5f color:Main_Color_LightGray];
    }
    return _dateLB;
}
-(void)setModel:(GYMineLikeProductInfoModel *)model
{
    _model = model;
    NSString *picurl = [NSString stringWithFormat:@"%@%@",_model.picurl,kProductImgThumbnailSuffix];
    [_imageIV sd_setImageWithURL:[NSURL URLWithString:picurl] placeholderImage:[UIImage imageNamed:@"default_goods"]];
    _nameLB.text = _model.name;
    _typeLB.text = [NSString stringWithFormat:@" %@ ",_model.protypename];
    
    NSString *unit = _model.unit?:@"";
//    _countLB.text = [NSString stringWithFormat:@"数量：%@%@",_model.count?:@"0",unit];
    NSString *priceUnit = _model.unit?[NSString stringWithFormat:@"元/%@",unit]:@"元";
    NSString *prices = [NSString stringWithFormat:@"%ld",_model.price];
    NSString *price = [NSString stringWithFormat:@"%@%@",prices,priceUnit];
    NSMutableAttributedString *mastr = [[NSMutableAttributedString alloc]initWithString:price];
    [mastr addAttribute:NSFontAttributeName value:SYSTEMFONT(10) range:[price rangeOfString:priceUnit]];
    [mastr addAttribute:NSFontAttributeName value:SYSTEMFONT(20) range:[price rangeOfString:prices]];
    _priceLB.attributedText = mastr;
    NSString *province = [_model.provincename stringByReplacingOccurrencesOfString:@"省" withString:@""];
    NSString *city = [_model.cityname stringByReplacingOccurrencesOfString:@"市" withString:@""];
    NSString *area = [NSString stringWithFormat:@" %@%@ ",province,city];
    _areaLB.text = area;
    
//    NSString *dealCount = [NSString stringWithFormat:@"累计成交量：%@%@",_model.salecount?:@"0",unit];
//    _dealCountLB.text = dealCount;
    _dateLB.text = _model.createtime;
}
#pragma mark - event
#pragma mark - method
+(CGFloat)finalHeight
{
    return WFCGFloatY(104);
}
#pragma mark - life

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.imageIV];
        [self.contentView addSubview:self.nameLB];
        [self.contentView addSubview:self.typeLB];
//        [self.contentView addSubview:self.countLB];
        [self.contentView addSubview:self.priceLB];
        [self.contentView addSubview:self.areaLB];
//        [self.contentView addSubview:self.dealCountLB];
        [self.contentView addSubview:self.deleteBtn];
        [self.contentView addSubview:self.dateLB];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
#pragma mark - delegate
-(void)callback:(id)sender
{
    _typeLB.x = _nameLB.right + WFCGFloatX(5);
    _typeLB.centerY = _nameLB.centerY;
    _areaLB.x = _priceLB.right + WFCGFloatX(6);
    
    [WFFunctions WFUIaddbordertoView:_areaLB radius:WFCGFloatY(3) width:0.0f color:nil];
}
@end
